<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>javascript 阶段</title>
    <style>
        div {
            height: 50px;
            border-bottom: 3px solid #fff;
        }
    </style>
</head>
<body>

    <script>
        // 定义变量 记录一维数组
        var arr = ["red","green","blue"];

        // 定义变量，记录二维数组（索引值）
        var elements = [
            ["red","green","blue"],
            ["pink","orange","purple"],
            ["deepskyblue","yellowgreen","darkred"]
        ]
        // 问题：如何取出 purple 这个颜色 ？
        // var color = elements[1][2];
        // console.log(color);// purple


        // 循环二维数组
        // 定义字符串变量
        var str = "";
        // 循环elements数组
        for(var i = 0 ; i < elements.length ; i ++ ){
            // 循环elements嵌套的数组
            for(var j = 0 ; j < elements[i].length ; j ++){
                // 拼接html代码字符串 
                str+= "<div style='background-color:"+elements[i][j]+";'></div>"
            }
        }
        // 渲染字符串
        document.write(str);


    </script>
</body>
</html>